package homework3;

import java.util.Random;

public class Main {

	public static void main(String[] args) {
		
		Random rand = new Random();
		
		Machine m = new Aircraft(100);
		
		System.out.println("初始能量值："+m.getEnergy());
		
		outer:while(true) {
			int op = rand.nextInt(10);
			switch(op) {
			case 0 :
				if(m.getEnergy()<10) {
					break outer;
				}else {
					Roadable r= (Roadable)m;
					r.run();
				}
				break;
			case 1 :
				if(m.getEnergy()<15) {
					break outer;
				}else {
					Voyageable v= (Voyageable)m;
					v.voyage();
				}
				break;
			case 2 :
				if(m.getEnergy()<25) {
					break outer;
				}else {
					Flyable v= (Flyable)m;
					v.fly();
				}
				break;
			default :
				System.out.println("无效操作！");
				break;
			}
		}
		System.out.println("剩余能量值："+m.getEnergy());
	}

}
